import { _decorator, animation, Animation, Component, Enum, Node } from "cc";
import { PlantsState, PlantType } from "./Global";
const { ccclass, property } = _decorator;

@ccclass("Plant")
export class Plant extends Component {
  plantState: PlantsState = PlantsState.Disable;

  @property({ type: Enum(PlantType) })
  public plantType: PlantType;

  protected start(): void {
    this.transitionToDisable();
  }

  update(deltaTime: number) {
    switch (this.plantState) {
      case PlantsState.Disable:
        this.disableUpdate();
        break;
      case PlantsState.Enable:
        this.enableUpdate();
        break;
    }
  }

  /**
   * 未激活状态更新逻辑
   */
  disableUpdate() {}
  /**
   * 激活状态更新逻辑
   */
  enableUpdate() {
    
  }
  /**
   * 转变到未激活状态
   */
  transitionToDisable() {
    this.plantState = PlantsState.Disable;
    this.getComponent(animation.AnimationController).enabled = false;
  }
  /**
   * 转变到激活状态
   */
  transitionToEnable() {
    this.plantState = PlantsState.Enable;
    this.getComponent(animation.AnimationController).enabled = true;
  }
}
